#light
#load "primitives.fs"
#load "problems.fs"
#load "basic2dplot.fs"

open LambdaMop.Problems
open LambdaMop.Primitives
open LambdaMop.Plotting

(*Example 1: Using the Dominated Compare function *)

dominatedCompare [1;1;1;3] [1;1;4;3] |> printfn "%i"
dominatedCompare [1] [2] |> printfn "%i"
dominatedCompare [1;1] [1;2] |> printfn "%i"
dominatedCompare [1.;1.] [1.;1.] |> printfn "%i"
dominatedCompare [2.;2.] [2.;2.] |> printfn "%i"
dominatedCompare [3.;2.] [3.;4.] |> printfn "%i"
//Throws a DifferentLenghts exception.
//dominatedCompare [3.;2.] [3.] |> printfn "%i" 

(*Example 2: Using the NonDominatedList Data Structure *)

let f1 (x: float []) = x.[0]
let f2 (x: float []) = x.[1]
let f3 (x: float []) = x.[2]

let list = NonDominatedList([f1;f2;f3])

let sols = [[|3.;3.;3.|];[|4.;3.;2.|];
            [|2.;3.;3.|];[|5.;1.;1.|];
            [|6.;0.;1.|];[|5.;5.;5.|];
            [|1.;1.;1.|];[|0.;0.;0.|]]

let addAndShow s = 
    list.Add s |> 
        fun x -> if x then "inserted\n" 
                 else "not inserted\n" 
        |> print_string
    printfn "%A" (list.Value)

List.iter addAndShow sols

(*Example 3: Using the DominatedRandomSearch Algorithm 
    This one _Needs_ to be compiled
 *)
let problem = zdt2 2

let solutions = dominatedRandomSearch problem 100000

printf "Solutions \n"

solutions |> print_any

printf "Objs \n"

let to_TupleList x =
    let to_Tuple x = 
        match x with
        | x::y::[] -> (x,y)
    List.map to_Tuple x

solutions |> List.map (fun x -> (invMap x problem.functions 
|> List.of_seq)) |> to_TupleList  
|> plot
System.Console.ReadLine();

(* Example 4: Spea2 *)
